﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using File_Manager.Models;

namespace File_Manager.Controllers
{
    public class JsonController : Controller
    {
        private CYTContext db = new CYTContext();
        //
        // GET: /Json/PostPendientes
        [Authorize(Roles = "Admin")]
        public ActionResult PostPendientes()
        {
            var postP = (from m in db.Post_CYT
                         where m.idStatus == 1
                         select m.id).Count().ToString();

            return Json(postP);
        }

        //
        // GET: /Json/CuotasPendientes
        [Authorize(Roles = "Admin")]
        public ActionResult CuotasPendientes()
        {
            var cuotasP = (from m in db.User_I
                         where m.idStatus == 1
                         select m.UserName).Count().ToString();

            return Json(cuotasP);
        }

        //
        // GET: /Json/UserName
        public ActionResult UserName()
        {
            var name = (from m in db.User_I
                        where m.UserName == User.Identity.Name
                        select m.name).FirstOrDefault();

            var lastName = (from m in db.User_I
                            where m.UserName == User.Identity.Name
                            select m.last_name).FirstOrDefault();

            var name_all = name +" "+ lastName;

            if (name_all==" ")
            {
                name_all = User.Identity.Name;
            }

            return Json(name_all);
        }
    }
}
